package com.lxj.lambda;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.lxj.charactor.Hero;

/**
 * TestLambda2
 */
public class TestLambda2 {

    public static void main(String[] args) {
        Random r = new Random();
        List<Hero> heros = new ArrayList<>();

        for (int i = 0; i < 5; i++) {
            heros.add(new Hero("heros_"+i, r.nextInt(1000), r.nextInt(100)));
        }

        // HeroChecker checker = new HeroChecker(){
        
        //     @Override
        //     public boolean test(Hero hero) {
        //         return (hero.hp>100 && hero.damage < 50);
        //     }
        // };

        // filter(heros,hero->hero.hp>100 && hero.damage < 50);
        heros.stream().filter(h->h.hp>100 && h.damage < 50).forEach(h -> System.out.println(h.name));

    }

    private static void filter(List<Hero> heros, HeroChecker checker) {
        for (Hero hero : heros) {
            if(checker.test(hero)) {
                System.out.println(hero);
            }
        }
    }
}